'use strict'

class articledetail{
  constructor(){
    this.param = '/'
  }
  async get(c){
    let a = c.service.fun;
    let art_id = c.query.article_id;
    let user_id = c.query.user_id;
    console.log(user_id);
    //返回文章信息
    let data3 = await c.service.pqorm.model('article_list c')
      .leftJoin('user_list u','c.poster_id=u.user_id')
      .where({article_id:`${art_id}`})
      .select('article_id,article_title,article_txt,article_time,poster_id,user_head,user_name,article_img');
      
    let iflike;
    let bb = await a.sel('like_list','',[],c.service.pool);
    let aa = bb.rows.some(item=>{
      return user_id == item.like_user_id
    })
    if(aa){
      let line = await a.sel('like_list',{'like_user_id':`${user_id}`},['liked_article_id'],c.service.pool);
      let my_liked_article_id = `${art_id}`;
      for(let i=0;i<line.rows.length;i++){
        let {liked_article_id} = line.rows[i];
        if(liked_article_id == my_liked_article_id){
          iflike = true;
          break;
        }else{
          iflike = false;
        }
      }
    }else{
      for(let i=0;i<bb.rows.length;i++){
        iflike = false;
      }
    }
      
    //先找出点赞的人
    //let data1 =await a.sel('like_list',{'liked_article_id':`${art_id}`},['like_id','like_user_id'],c.service.pool);
    let condition1={
      liked_article_id:`${art_id}`
    }
    let data1 = await c.service.pqorm.model('like_list l')
      .leftJoin('user_list u','l.like_user_id=u.user_id')
      .where(condition1)
      .select('like_id,like_user_id,user_name')
    
    //然后是评论者的信息从user—list和评论表中找，
    let condition = {
      comment_article_id:`${art_id}`
    };
    let data2 =await c.service.pqorm.model('comment_list c')
                                .leftJoin('user_list u','c.comment_user_id=u.user_id')
                                .where(condition)
                                .select('user_id,user_head,user_name,comment_txt,comment_time,comment_id');
    console.log(data2.rows);
    console.log(data3);
    let data11 = data1.rows;
    let data22 = data2.rows;
    let data33 = data3.rows[0];
    let data = {data11,data22,data33,iflike};

    c.send({
        type:'object',
        data:data
    })
  }
}
module.exports = articledetail;
